#if defined(_MSC_VER)
#pragma once
#endif

#ifndef LM_TEXTURE_BILERP_H
#define LM_TEXTURE_BILERP_H

#include "../core/lm.h"
#include "../core/texture.h"
#include "../core/texturemap.h"

template<typename T>
class Bilerp : public Texture<T> {
public:
	Bilerp(Reference<TextureMap> m, const T &t00, const T &t01, const T &t10, const T &t11) {
		mapping = m;
		v00 = t00;
		v01 = t01;
		v10 = t10;
		v11 = t11;
	}
	T Evaluate(const Intersection &isect) {
		float s, t;
		float zombie;	// zombie variable, not used
		mapping->Map(isect, &s, &t,*zombie,*zombie,*zombie,*zombie);
		return	(1-st.s) * (1-st.t) * v00 +
				(1-st.s) * (  st.t) * v01 +
				(  st.s) * (1-st.t) * v10 +
				(  st.s) * (  st.t) * v11;
	}
	~Bilerp() {
		mapping = NULL;
	}
private:
	Reference<TextureMap> mapping;
	T v00, v01, v10, v11;
};

#endif	// LM_TEXTURE_BILERP_H